//
//  main.c
//  线性表顺序存储与实现
//
//  Created by ZJ on 2018/7/13.
//  Copyright © 2018年 iCatch Technology Inc. All rights reserved.
//

#include <stdio.h>
#include "seqlist.h"
#include <stdlib.h>

typedef struct Teacher {
    int age;
    char name[64];
}Teacher;

int main(int argc, const char * argv[]) {
    // insert code here...
    
    int ret = 0;
    SeqList* list = NULL;
    
    Teacher t1, t2, t3, t4, t5;
    t1.age = 31;
    t2.age = 32;
    t3.age = 33;
    t4.age = 34;
    t5.age = 35;

    list = SeqList_Create(10);
    if (list == NULL) {
        ret = -1;
        printf("func SeqList_Create() ret: %d", ret);
        return ret;
    }
    
    ret = SeqList_Insert(list, (SeqListNode *)&t1, 0); // 头插法
    ret = SeqList_Insert(list, (SeqListNode *)&t2, 0);
    ret = SeqList_Insert(list, (SeqListNode *)&t3, 0);
    ret = SeqList_Insert(list, (SeqListNode *)&t4, 0);
    ret = SeqList_Insert(list, (SeqListNode *)&t5, 0);

    // 遍历
    for (int i = 0; i < SeqList_Length(list); i++) {
        Teacher* node = (Teacher *)SeqList_Get(list, i);
        if (node == NULL) {
            printf("SeqList_Get failed.");
            continue;
        }
        
        printf("node->age: %d ", node->age);
    }
    
    printf("\n");
    // 删除链表中的节点
    while (SeqList_Length(list) > 0) {
        SeqList_Delete(list, 0);
    }
    
    SeqList_Destroy(list);
    
    printf("Hello, World!\n");
    return 0;
}
